package com.wiim.ui;

import com.wiim.common.ConstantValue;
import com.wiim.common.Utilities;
import com.wiim.libs.WorldUtilities;
import com.wiim.nhapnhap.CustomFragmentActivity;
import com.wiim.nhapnhap.R;
import com.wiim.tab.TabWidget;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TabDiaDiem extends CustomFragmentActivity implements OnClickListener {
	private Button btnLogOut;
	private Button btnThongtin;
	private Button btnHoi;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.main_three);
		super.onCreate(savedInstanceState);
		btnLogOut = (Button) getParent().findViewById(R.id.btnLogOut);
		btnThongtin = (Button) getParent().findViewById(R.id.btnThongtin);
		btnHoi = (Button) getParent().findViewById(R.id.btnHoi);

		if (!isOnActivityResult) {
			if (this.mListView.size() > 0) {
				this.startFragment(this.mListView.get(this.mListView.size() - 1));
			} else {
				this.startFragment(ConstantValue.DIADIEM_FRAGMENT);
			}
		}

		TabWidget.tabHost.getTabWidget().getChildAt(2).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.v("HAI", "tab_home click");
				if (Utilities.getGlobalVariable(getParent()).currentTab == ConstantValue.TAB_DIADIEM && mListView.size() > 1) {
					onBackPressed();
				} else {
					TabWidget.tabHost.setCurrentTab(2);
					if (mListView.size() > 1) {
						returnToFragment(mListView.get(2), false);
					}
				}
			}
		});
		Utilities.getGlobalVariable(getParent()).currentTab = ConstantValue.TAB_DIADIEM;
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		btnLogOut.setOnClickListener(this);
		btnThongtin.setOnClickListener(this);
		btnHoi.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v == btnLogOut) {
			replaceFragment(ConstantValue.DOITHUONG_FRAGMENT, false);
		}
		if (v == btnThongtin) {
			replaceFragment(ConstantValue.THONGTIN_TK_FRAGMENT, false);
		}
		if (v == btnHoi) {
			WorldUtilities.showDialogNoBack(TabDiaDiem.this, "version 1.0").show();
		}

	}

}
